package com.woniuxy.microsportsserver.weightmag.controller;

import com.woniuxy.common.bean.PageDto;
import com.woniuxy.common.bean.ResultMsg;
import com.woniuxy.microsportsserver.bean.WeightAnalysisInfo;
import com.woniuxy.microsportsserver.bean.WeightInfo;
import com.woniuxy.microsportsserver.weightmag.service.IWeightService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/weight")
@RestController
public class WeightController {

    @Resource
    private IWeightService weightService;


    //查询页面一数据步数的总和
    @GetMapping(value="/all",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg findAll(WeightInfo weightInfo ,Integer pageNum,Integer pageSize){
     //   List<WeightInfo> all = weightService.findAll(weightInfo);
        // return JSONObject.toJSONString(new ResultMsg().setCode(200).setMessage("操作成功").setData(all));
      //  return new ResultMsg().setCode(200).setMessage("操作成功").setData(all);
        ResultMsg resultMsg = new ResultMsg();
        PageDto pageDto = weightService.findAll(weightInfo,pageNum, pageSize);
        if (pageDto == null) {
            return resultMsg.setCode(10000).setMessage("系统繁忙，请稍后再试");
        }
        return resultMsg.setCode(200).setMessage("查询成功").setData(pageDto);
    }

    //一个人的详细信息
    @GetMapping(value = "/one",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg allRecords(WeightInfo weightInfo){
        WeightInfo data = weightService.findOneByUserId(weightInfo);
        return new ResultMsg().setCode(200).setMessage("操作成功").setData(data);
    }


    //各年龄段平均体重
    @GetMapping(value = "/allAvgWeight",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg allAvgWeight(){
        List<WeightAnalysisInfo> data = weightService.findWeightByAgeType();
/*        String arr1 = new arr[8];
        String arr2 =
        data.forEach(e->{

        });*/
        return new ResultMsg().setCode(200).setMessage("操作成功").setData(data);
    }
    //18岁以上的成年人体重分步
    @GetMapping(value = "/WeightPercentage",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg WeightPercentage(){
        List<WeightAnalysisInfo> data = weightService.WeightPercentage();
        return new ResultMsg().setCode(200).setMessage("操作成功").setData(data);
    }

}
